﻿/*
 Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
 For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
CKEDITOR.dialog.add("textfield", function (b) {
  console.log(b.lang.common,b.lang.forms.textfield,"b.lang.forms.textfield")
	function e(a) {
		a = a.element
		var b = this.getValue()
		b ? a.setAttribute(this.id, b) : a.removeAttribute(this.id)
	}
	function f(a) {
		a = a.hasAttribute(this.id) && a.getAttribute(this.id)
		this.setValue(a || "")
	}
	var g = { email: 1, password: 1, search: 1, tel: 1, text: 1, url: 1 }
  var aaaaaaa
	return {
		title: b.lang.forms.textfield.title,
		minWidth: 300,
		minHeight: 150,
		getModel: function (a) {

			a = a.getSelection().getSelectedElement()
      console.log(a,'aaa')
			return !a || "input" != a.getName() || (!g[a.getAttribute("type")] && a.getAttribute("type")) ? null : a
		},
		onShow: function () {
			var a = this.getModel(this.getParentEditor())
      console.log(a,'assssssaa')
			a && this.setupContent(a)

		},
		onOk: function () {
			var a = this.getParentEditor(),
				b = this.getModel(a),
				c = this.getMode(a) == CKEDITOR.dialog.CREATION_MODE
			c && ((b = a.document.createElement("input")), b.setAttribute("type", "text"))
			b = { element: b }
			c && a.insertElement(b.element)
			this.commitContent(b)
			c || a.getSelection().selectElement(b.element)
		},
		onLoad: function () {
			this.foreach(function (a) {
        console.log(a,'assssssaabbbbbbb')
				a.getValue && (a.setup || (a.setup = f), a.commit || (a.commit = e))
			})
		},
		contents: [
			{
				id: "info",
				label: b.lang.forms.textfield.title,
				title: b.lang.forms.textfield.title,
				elements: [
					{
						type: "hbox",
						widths: ["50%", "50%"],
						children: [
              // validate: CKEDITOR.dialog.validate.integer(b.lang.common.validateNumberFailed)
              // default: "20,1",
							{ id: "size", type: "text", label: b.lang.forms.textfield.charWidth, default: "20", accessKey: "C", style: "width:50px",validate: CKEDITOR.dialog.validate.integer(b.lang.common.invalidRowSpan)  },
							{ id: "maxLength", type: "text", label: b.lang.forms.textfield.maxChars, default: "50", accessKey: "M", style: "width:50px", validate: CKEDITOR.dialog.validate.integer(b.lang.common.invalidRowSpan) },
            ],
						onLoad: function () {
							CKEDITOR.env.ie7Compat && this.getElement().setStyle("zoom", "100%")
						}
					},

					{
						id: "_cke_saved_name",
						type: "select",
						label: "零件类型",
						default: "",
						accessKey: "N",
						//下拉列表
						items: CKEDITOR.ConfigSelect.textfield,
						setup: function (a) {
							this.setValue(a.data("cke-saved-name") || a.getAttribute("name") || "")
						},
						commit: function (a) {
							a = a.element
              aaaaaaa = this.getValue()
							this.getValue() ? a.data("cke-saved-name", this.getValue()) : (a.data("cke-saved-name", !1), a.removeAttribute("name"))
						}
					},
					{
						id: "value",
						type: "checkbox",
						label: "是否外委零件",
						default: "",
						// accessKey: "M",
						value: "",
					  setup: function (a) {
							this.setValue(a.getAttribute("value"))
						},
						commit: function (a) {
							a = a.element
              this.getValue()?a.setAttribute("value", 'true'):a.removeAttribute("value")
						}
					},
					{
						id: "required",
						type: "checkbox",
						label: "零件更换原因",
						default: "",
						accessKey: "Q",
						value: "required",
						// setup: CKEDITOR.plugins.forms._setupRequiredAttribute,
            setup: function (a) {
							this.setValue(a.getAttribute("required"))
						},
						commit: function (a) {
							a = a.element
							this.getValue() ? a.setAttribute("required", "required") : a.removeAttribute("required")
						}
					},
					{
						type: "checkbox",
						label: "零件更换数量",
						default: "",
						accessKey: "S",
						value: "",
						setup: function (a) {
							this.setValue(a.getAttribute("checked"))
						},
						commit: function (a) {
							var b = a.element
							if (CKEDITOR.env.ie) {
								var c = !!b.getAttribute("checked"),
									e = !!this.getValue()
								c != e && ((c = CKEDITOR.dom.element.createFromHtml('\x3cinput type\x3d"checkbox"' + (e ? ' checked\x3d"checked"' : "") + "/\x3e", d.document)), b.copyAttributes(c, { type: 1, checked: 1 }), c.replace(b), d.getSelection().selectElement(c), (a.element = c))
							} else (a = this.getValue()), CKEDITOR.env.webkit && (b.$.checked = a), a ? b.setAttribute("checked", "checked") : b.removeAttribute("checked")
						}
					}
				]
			}
		]
	}
})
